package k.b.s;

import java.util.ArrayList;

import k.b.s.model.ItemRowModel;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class DBTestView extends Activity{
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dtv);

	}
	public void onClickDTV(View v){
		Database databaseOpenHelper = new Database(this);
		SQLiteDatabase database = null;
		TextView textCount = (TextView)findViewById(R.id.textView1);
		String[] select = {"isread"};


		database = databaseOpenHelper.getReadableDatabase();

//		Cursor cursor = database.query("ITEM_TB", null, "channel='http://www.oesf.jp/modules/news/index.php?page=rss'" ,null, null, null, null);
		Cursor cursor = database.query("ITEM_TB", select , null ,null, null, null, null);

		StringBuilder text = new StringBuilder();

		if(cursor != null){
			while(cursor.moveToNext()){
				String t = cursor.getString(cursor.getColumnIndex("isread"));
//				String d = cursor.getString(cursor.getColumnIndex("description"));
//				text.append("Title:" + t + "\nDescription:" + d + "\n");
				text.append("Title:" + t + "\n");
			}
			textCount.setText(text.toString());
		}
		if(database != null){
			databaseOpenHelper.close();
			Log.v("DatabaseSample","Succeeded in close the database.");
		}
	}

	public void dropTB(View v){
		String channel = "http://www3.nhk.or.jp/rss/news/cat0.xml";
		OperationDB.deleteChannel(channel, this);
//		ArrayList<ItemRowModel> rows = OperationDB.getItemTB(this);
//		OperationDB.setIsRead(rows.get(2), this);
	}
}
